#!/usr/bin/env bash

rm -rf ./dist/*
cd src
pkgName="gomonitor-server"
#arm编译
GOARM=7 GOARCH=arm64 GOOS=linux  go build -ldflags '-w -s' -o gomonitor-server
mkdir ../dist/${pkgName}_arm64_v7
mv -f gomonitor-server ../dist/${pkgName}_arm64_v7/${pkgName}_arm64_v7
cp ../scripts/*.sh ../dist/${pkgName}_arm64_v7/

#linux
GOARCH=amd64 GOOS=linux  go build -ldflags '-w -s' -o gomonitor-server
mkdir ../dist/${pkgName}_amd64_linux
mv -f gomonitor-server ../dist/${pkgName}_amd64_linux/${pkgName}_amd64_linux
cp ../scripts/*.sh ../dist/${pkgName}_amd64_linux/


#darwin
GOARCH=amd64 GOOS=darwin  go build -ldflags '-w -s' -o gomonitor-server
mkdir ../dist/${pkgName}_amd64_darwin
mv -f gomonitor-server ../dist/${pkgName}_amd64_darwin/${pkgName}_amd64_darwin
cp ../scripts/*.sh ../dist/${pkgName}_amd64_darwin/

cd ../dist/
if [ `uname` = "Darwin" ]
then
  gtar -zcvf gomonitor-server_arm64_v7.tar.gz gomonitor-server_arm64_v7
  gtar -zcvf gomonitor-server_amd64_linux.tar.gz gomonitor-server_amd64_linux
  gtar -zcvf gomonitor-server_amd64_darwin.tar.gz gomonitor-server_amd64_darwin
else
  tar -zcvf gomonitor-server_arm64_v7.tar.gz gomonitor-server_arm64_v7
  tar -zcvf gomonitor-server_amd64_linux.tar.gz gomonitor-server_amd64_linux
  tar -zcvf gomonitor-server_amd64_darwin.tar.gz gomonitor-server_amd64_darwin
fi

rm -rf gomonitor-server_arm64_v7
rm -rf gomonitor-server_amd64_linux
rm -rf gomonitor-server_amd64_darwin

